﻿using STTech.BytesIO.Serial;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPF.BytesIO.Serial.Models;

namespace WPF.BytesIO.Serial.ModelViews
{
    public class MainViewModel : NotifyObject
    {

        #region TestInfo
        /// <summary>
        /// Test Information
        /// </summary>
        public TestInfo TestInfo { get; set; }
        #endregion

        public Status SerialStatus { get; set; }


        //private string _ComPort;
        ///// <summary>
        ///// COM
        ///// </summary>
        //[System.Xml.Serialization.XmlAttribute()]
        //public string ComPort
        //{
        //    get { return _ComPort; }
        //    set
        //    {
        //        _ComPort = value;
        //        OnPropertyChanged("ComPort");
        //    }
        //}

        private Dictionary<string, string> _PortNames;
        /// <summary>
        /// PortNames
        /// </summary>
        [System.Xml.Serialization.XmlIgnore]
        public Dictionary<string, string> PortNames
        {
            get { return _PortNames; }
            set
            {
                _PortNames = value;
                OnPropertyChanged("PortNames");
            }
        }

        public void LoadPortNames()
        {
            var ports = new Dictionary<string, string>();

            SerialClient serialClient = new SerialClient();

            string[] portNames = serialClient.GetPortNames();

            if (portNames != null && portNames.Length > 0)
            {

                foreach (var item in portNames)
                {
                    ports.Add(item, item);
                }

            }
            ports.Add("Com999", "Com999");

            this.PortNames = ports;
        }

        public MainViewModel()
        {

            TestInfo = new TestInfo();

            SerialStatus = new Status("Serial Client No Connect", MyBrushes.Red);

            LoadPortNames();
        }

    }
}
